package com.hnevc.wangyu;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private View turnOnBtn;
    private View turnOffBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        turnOnBtn = findViewById(R.id.turn_btn);
        turnOffBtn = findViewById(R.id.turnOff_btn);
    }

    private void initData() {

    }

    private void initEvent() {
        turnOnBtn.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                //通过意图启动Service
                Intent intent = new Intent(MainActivity.this,MyService.class);
                startService(intent);
            }
        });
        turnOffBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,MyService.class);
                stopService(intent);
            }
        });
    }
}